home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Caml Light 0.61 / Source / src / lib / list.mli < prev    next >
Encoding:
Text File  |  1993-09-24  |  4.9 KB  |  96 lines  |  [TEXT/MPS ]

  1. (* Operations on lists *)
  2.  
  3. value list_length : 'a list -> int
  4.         (* Return the length (number of elements) of the given list. *)
  5.   and prefix @ : 'a list -> 'a list -> 'a list
  6.         (* List concatenation. *)
  7.   and hd : 'a list -> 'a
  8.         (* Return the first element of the given list. Raise
  9.            [Failure "hd"] if the list is empty. *)
  10.   and tl : 'a list -> 'a list
  11.         (* Return the given list without its first element. Raise
  12.            [Failure "tl"] if the list is empty. *)
  13.   and rev : 'a list -> 'a list
  14.         (* List reversal. *)
  15.   and map : ('a -> 'b) -> 'a list -> 'b list
  16.         (* [map f [a1; ...; an]] applies function [f] to [a1, ..., an],
  17.            and builds the list [[f a1; ...; f an]]
  18.            with the results returned by [f]. *)
  19.   and do_list : ('a -> 'b) -> 'a list -> unit
  20.         (* [do_list f [a1; ...; an]] applies function [f] in turn to
  21.            [a1; ...; an], discarding all the results. It is equivalent to
  22.        [begin f a1; f a2; ...; f an; () end]. *)
  23.   and it_list : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a
  24.         (* [it_list f a [b1; ...; bn]] is [f (... (f (f a b1) b2) ...) bn]. *)
  25.   and list_it : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b
  26.         (* [list_it f [a1; ...; an] b] is [f a1 (f a2 (... (f an b) ...))]. *)
  27.   and map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list
  28.         (* [map2 f [a1; ...; an] [b1; ...; bn]] is [[f a1 b1; ...; f an bn]].
  29.        Raise [Invalid_argument "map2"] if the two lists have
  30.            different lengths. *)
  31.   and do_list2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> unit
  32.         (* [do_list2 f [a1; ...; an] [b1; ...; bn]] calls in turn
  33.            [f a1 b1; ...; f an bn], discarding the results.
  34.        Raise [Invalid_argument "do_list2"] if the two lists have
  35.        different lengths. *)
  36.   and it_list2 : ('a -> 'b -> 'c -> 'a) -> 'a -> 'b list -> 'c list -> 'a
  37.         (* [it_list2 f a [b1; ...; bn] [c1; ...; cn]] is
  38.                [f (... (f (f a b1 c1) b2 c2) ...) bn cn].
  39.        Raise [Invalid_argument "it_list2"] if the two lists have
  40.        different lengths. *)
  41.   and list_it2 : ('a -> 'b -> 'c -> 'c) -> 'a list -> 'b list -> 'c -> 'c
  42.         (* [list_it2 f [a1; ...; an] [b1; ...; bn] c] is
  43.                [f a1 b1 (f a2 b2 (... (f an bn c) ...))].
  44.        Raise [Invalid_argument "list_it2"] if the two lists have
  45.        different lengths. *)
  46.   and flat_map : ('a -> 'b list) -> 'a list -> 'b list
  47.         (* [flat_map f [l1; ...; ln]] is [(f l1) @ (f l2) @ ... @ (f ln)]. *)
  48.   and for_all : ('a -> bool) -> 'a list -> bool
  49.         (* [for_all p [a1; ...; an]] is [(p a1) & (p a2) & ... & (p an)]. *)
  50.   and exists : ('a -> bool) -> 'a list -> bool
  51.         (* [exists p [a1; ...; an]] is [(p a1) or (p a2) or ... or (p an)]. *)
  52. ;;
  53.  
  54. value mem : 'a -> 'a list -> bool
  55.         (* [mem a l] is true if and only if [a] is structurally equal (see
  56.            module [eq]) to an element of [l]. *)
  57.   and memq : 'a -> 'a list -> bool
  58.         (* [memq a l] is true if and only if [a] is physically equal (see
  59.            module [eq]) to an element of [l]. *)
  60.   and except : 'a -> 'a list -> 'a list
  61.         (* [except a l] returns the list [l] where the first element
  62.            structurally equal to [a] has been removed.
  63.            The list [l] is returned unchanged if it does not contain [a]. *)
  64.   and exceptq : 'a -> 'a list -> 'a list
  65.         (* Same as [except], with physical equality instead of structural
  66.            equality. *)
  67.   and subtract : 'a list -> 'a list -> 'a list
  68.         (* [subtract l1 l2] returns the list [l1] where all elements
  69.            structurally equal to one of the elements of [l2]
  70.            have been removed. *)
  71.   and union : 'a list -> 'a list -> 'a list
  72.         (* [union l1 l2] appends before list [l2] all the elements of list [l1]
  73.            that are not structurally equal to an element of [l2]. *)
  74.   and intersect : 'a list -> 'a list -> 'a list
  75.         (* [intersect l1 l2] returns the list of the elements of [l1] that
  76.            are structurally equal to an element of [l2]. *)
  77.   and index : 'a -> 'a list -> int
  78.         (* [index a l] returns the position of the first element of list [l]
  79.            that is structurally equal to [a]. The head of the list has
  80.            position 0. Raise [Not_found] if [a] is not present in [l]. *)
  81. ;;
  82. value assoc : 'a -> ('a * 'b) list -> 'b
  83.         (* [assoc a l] returns the value associated with key [a] in the list of
  84.            pairs [l]. That is,
  85.              [assoc a [ ...; (a,b); ...] = b]
  86.            if [(a,b)] is the leftmost binding of [a] in list [l].
  87.            Raise [Not_found] if there is no value associated with [a] in the
  88.            list [l]. *)
  89.   and assq :  'a -> ('a * 'b) list -> 'b
  90.         (* Same as [assoc], but use physical equality instead of structural
  91.            equality to compare keys. *)
  92.   and mem_assoc : 'a -> ('a * 'b) list -> bool
  93.         (* Same as [assoc], but simply return true if a binding exists,
  94.            and false if no bindings exist for the given key. *)
  95. ;;
  96.